﻿using System;
using System.Threading;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
//using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Athena
{
    public partial class Splash : Form
    {
        public Splash()
        {
            InitializeComponent();
            Bitmap b = new Bitmap(this.BackgroundImage);
            //this is not having the effect you want :) ... 
            //b.MakeTransparent(b.GetPixel(1, 1));
            this.BackgroundImage = b;
        }

        private static Splash _SplashForm;
        public static Splash SplashForm
        {
            get {
                if (_SplashForm == null)
                    _SplashForm = new Splash();
                return _SplashForm; 
            }
            set { _SplashForm = value; }
        }

        static long _StartTick;

        /// <summary>
        /// Shows the Splash screen
        /// </summary>
        public static void Start()
        {
            _StartTick = DateTime.Now.Ticks;
            SplashForm.Show();
        }

        /// <summary>
        /// If the Splash screen has been displayed for at least 5 seconds, close it
        /// </summary>
        public static void End()
        {
            End(5000);
        }

        /// <summary>
        /// Closes the splash form after ensuring that it has been displayed for the specified 
        /// milliseconds.
        /// </summary>
        /// <param name="milliseconds">Number of milliseconds to show the splash screen</param>
        public static void End(int milliseconds)
        {
            int timeLeft = (int)new TimeSpan(DateTime.Now.Ticks - _StartTick).TotalMilliseconds;
            if (milliseconds - timeLeft > 0)
                System.Threading.Thread.Sleep(milliseconds - timeLeft);
            SplashForm.Close();
        }

        public static void DoSplash()
        {
            Splash sp = new Splash();
            sp.Show();
            Thread.Sleep(5000);
            sp.Close();
        }


    }
}
